<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/index' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>内容管理</el-breadcrumb-item>
      <el-breadcrumb-item>模板管理</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
    <el-row>
      <el-form :model="template" label-width="70px">
        <el-col :span="5">
          <el-form-item label="模板名称：" label-width="100px">
            <el-input v-model="template.name"></el-input>
          </el-form-item>
        </el-col>
      </el-form>
      <el-button type="primary" @click="search()" style="margin-left: 15px">查询</el-button>
      <el-button type="primary" @click="addtemplate" style="margin-left: 15px">上传模板</el-button>
    </el-row>
    <el-table
      :data="templatelist"
      border
      style="width: 100%">
      <el-table-column
        prop="name"
        label="页面模板名称"
        align="center">
      </el-table-column>
      <el-table-column
        prop="status"
        label="状态"
        align="center">
        <template slot-scope="scope">
          {{scope.row.status==0?'禁用':'启用'}}
        </template>
      </el-table-column>
      <el-table-column
        prop="updateTime"
        label="更新时间"
        align="center">
        <template slot-scope="scope">
          {{scope.row.updateTime|datefmt("YYYY-MM-DD HH:mm:ss")}}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="操作">
        <template slot-scope="scope">
          <el-dropdown  size="mini" split-button type="primary" trigger="click">
            操作
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item v-if="scope.row.status==0" @click.native="updatestatus(scope.row.id)">启用</el-dropdown-item>
              <el-dropdown-item v-if="scope.row.status==1" >下载</el-dropdown-item>
              <el-dropdown-item v-if="scope.row.status==1" @click.native="del(scope.row.id)">删除</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog
      title="上传模板"
      :visible.sync="DialogVisible"
      center :close-on-click-modal="false" @closed="crearbase">
      <el-upload
        class="upload-demo"
        drag
        :action="'/api/finance-service-cms/template/upload/'+user.id"
        :on-success="handleAvatarSuccess"
        multiple>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip" slot="tip">只能上传jpg/png文件，且不超过500kb</div>
      </el-upload>
    </el-dialog>
    </el-card>
  </div>
</template>

<script>
    export default {
        name: "Mbgl",
      data(){
          return{
            templatelist:[],
            template:{},
            user:{},
            isShow:false,
            DialogVisible:false
          }
      },
      methods:{
        handleAvatarSuccess(res, file) {
          this.$message({
            message:file.response.message,
            type: 'success'
          });
          this.DialogVisible=false;
          this.search();
        },
        del:function(id){
          this.$http.get("/finance-service-cms/template/del/"+id+"/"+this.user.id).then(
            (res)=>{
              if(res.data.success){
                this.$message({
                  message:res.data.message,
                  type: 'success'
                });
                this.search();
              }else{
                this.$message.error(res.data.message);
              }
            }
          );
        },
        addtemplate:function(){
          this.DialogVisible=true;
        },
        updatestatus:function(id){
          this.$http.get("/finance-service-cms/template/updatestatus/"+id+"/"+this.user.id).then(
            (res)=>{
              if(res.data.success){
                this.$message({
                  message:res.data.message,
                  type: 'success'
                });
                this.search();
              }else{
                this.$message.error(res.data.message);
              }
            }
          );
        },
        search:function () {
          this.$http.post("/finance-service-cms/template/templatelist",this.template).then(
            (res)=>{
              if(res.data.success){
                this.templatelist=res.data.result;
              }else{
                this.$message.error(res.data.message);
              }
            }
          );
        }
      },
      mounted() {
          this.user=JSON.parse(sessionStorage.getItem("user"));
          this.search();
      }
    }
</script>

<style scoped>

</style>
